#!/usr/bin/env python
# coding: utf-8

from datetime import datetime
import txmongo
from txmongo.dbref import DBRef

from twisted.internet import defer, reactor
 
@defer.inlineCallbacks
def example():
    mongo = yield txmongo.MongoConnection()

    db = mongo.ide  #  database
    members = mongo.ide_member.members  # collection
    sections = db.sections
    nodes = db.nodes

    daniel = {
                         'account': 'daniel',
                         'password':'7ce659a787c2a00bea4aae49e939b2d43fd12428',
                         'email':'daniel.yang.zhenyu@gmail.com',
                         'role': ['root'],
                        'title': '资深代码工',
                         'created': datetime.now(),
                         'updated': datetime.now(),
                         'last_login': datetime.now(),
                         'last_login_ip':'127.0.0.1',
                         'website': 'http://pinpin.us',
                         'location':'',
                         'bio':'',
                         'twitter':'',
                         'location':'',
                         'avatar':'',
                         'num': 1,
                         'blocked': False,
                         }
    table = {
                         'account': 'table',
                         'password':'7ce659a787c2a00bea4aae49e939b2d43fd12428',
                         'email':'tablef@gmail.com',
                         'title': '资深SP大忽悠',
                         'role': ['root'],
                        'num': 2,
                         'created': datetime.now(),
                         'updated': datetime.now(),
                         'last_login': datetime.now(),
                         'last_login_ip':'127.0.0.1',
                         }
    robot = {
                         'account': 'robot',
                         'password':'7ce659a787c2a00bea4aae49e939b2d43fd12428',
                         'email':'robot@gmail.com',
                         'title': '我是机器人',
                         'created': datetime.now(),
                         'updated': datetime.now(),
                         'last_login': datetime.now(),
                         'last_login_ip':'127.0.0.1',
                         'num':3,
                         'role': ['user'],
                         }
     
     
    r = yield members.insert([daniel, table, robot], True)
    
    s_beiju = {
                     'name':'cup',
                     'title':'爱杯具',
                     'order': 0,
                     'created': datetime.now(),
                     'updated': datetime.now(),
     }
    
    r_beiju = yield sections.insert(s_beiju, True)
    
    
    node_1 = {
                     'name':'fuguang',
                     'title':'富光',
                     'theme':'default',
                     'order': 0,
                     'desc':'中国驰名商标,市场占有率最大.',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_beiju)
     }
    
    node_2 = {
                     'name':'ide',
                     'title':'爱德售后',
                     'theme':'default',
                     'order': 1,
                     'desc':'富光•爱德售后服务.',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_beiju)
     }
    node_3 = {
                     'name':'member',
                     'title':'会员独享',
                     'theme':'default',
                     'order': 2,
                     'desc':'会员独享的优惠/特价.',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_beiju)
     }
    yield nodes.insert([node_1, node_2, node_3], True)
    
    
    s_life = {
                     'name':'life',
                     'title':'爱乐活',
                     'order': 1,
                     'created': datetime.now(),
                     'updated': datetime.now(),
     }
    
    r_life = yield sections.insert(s_life, True)
    
    
    node_1 = {
                     'name':'tea',
                     'title':'品茶',
                     'theme':'default',
                     'order': 0,
                     'desc':'茶与生活, 茶文化',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    node_2 = {
                     'name':'music',
                     'title':'音乐',
                     'theme':'default',
                     'order': 1,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    node_3 = {
                     'name':'movie',
                     'title':'电影',
                     'theme':'default',
                     'order': 2,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    
    node_4 = {
                     'name':'photo',
                     'title':'摄影',
                     'theme':'default',
                     'order': 3,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    
    node_5 = {
                     'name':'travel',
                     'title':'旅游',
                     'theme':'default',
                     'order': 4,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    
    node_6 = {
                     'name':'environment',
                     'title':'低碳/环保',
                     'theme':'default',
                     'order': 5,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    
    node_7 = {
                     'name':'health',
                     'title':'健康',
                     'theme':'default',
                     'order': 6,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    node_8 = {
                     'name':'pet',
                     'title':'宠物',
                     'theme':'default',
                     'order': 7,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }

    
    node_9 = {
                     'name':'chat',
                     'title':'唠叨',
                     'theme':'default',
                     'order': 8,
                     'desc':'宅人无罪,网唠有理',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    node_10 = {
                     'name':'ask',
                     'title':'提问',
                     'theme':'default',
                     'order': 9,
                     'desc':'以不懂就问为荣, 以不懂装懂为耻',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    node_11 = {
                     'name':'mm',
                     'title':'MM',
                     'theme':'default',
                     'order': 10,
                     'desc':'你懂得',
                     'acl':['adult'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_life)
     }
    
    yield nodes.insert([node_1, node_2, node_3, node_4, node_5, node_6
                        , node_7, node_8, node_9, node_10, node_11], True)
    
    
    
    s_fi = {
                     'name':'money',
                     'title':'爱理财',
                     'order': 2,
                     'created': datetime.now(),
                     'updated': datetime.now(),
     }
    r_fi = yield sections.insert(s_fi, True)
    
    node_1 = {
                     'name':'2ndhand',
                     'title':'换物',
                     'theme':'default',
                     'order': 0,
                     'desc':'把不用的东西拿出来,换换吧',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_fi)
     }
    
    node_2 = {
                     'name':'finance',
                     'title':'财经',
                     'theme':'default',
                     'order': 1,
                     'desc':'财经有什么好爱的...',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_fi)
     }
    
    node_3 = {
                     'name':'tuangou',
                     'title':'团购',
                     'theme':'default',
                     'order': 2,
                     'desc':'团购荟萃',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_fi)
     }
    
    yield nodes.insert([node_1, node_2, node_3], True)
    
    
    s_gadget = {
                     'name':'gadget',
                     'title':'爱玩具',
                     'order': 3,
                     'created': datetime.now(),
                     'updated': datetime.now(),
     }
    r_gadget = yield sections.insert(s_gadget, True)
    
    node_1 = {
                     'name':'apple',
                     'title':'Apple',
                     'theme':'default',
                     'order': 0,
                     'desc':'苹果粉丝/伪果粉皆宜',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_gadget)
     }
    
    node_2 = {
                     'name':'goolge',
                     'title':'Google',
                     'theme':'default',
                     'order': 1,
                     'desc':'Google粉丝/5毛党皆宜',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_gadget)
     }
    node_3 = {
                     'name':'nokia',
                     'title':'Nokia',
                     'theme':'default',
                     'order': 2,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_gadget)
     }
    
    node_4 = {
                     'name':'moto',
                     'title':'Motorola',
                     'theme':'default',
                     'order': 3,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_gadget)
     }
    
    yield nodes.insert([node_1, node_2, node_3, node_4], True)
    
    s_brand = {
                     'name':'brand',
                     'title':'爱品牌',
                     'order': 4,
                     'created': datetime.now(),
                     'updated': datetime.now(),
     }
    r_brand = yield sections.insert(s_brand, True)
    
    node_1 = {
                     'name':'european',
                     'title':'欧洲大牌',
                     'theme':'default',
                     'order': 0,
                     'desc':'LV, Gucci, Proda, Rolex,Vacheron Constantin...',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_brand)
     }
    node_2 = {
                     'name':'american',
                     'title':'花旗大牌',
                     'theme':'default',
                     'order': 1,
                     'desc':'Nike, M记, 雅诗兰黛...',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_brand)
     }
    
    node_3 = {
                     'name':'asian',
                     'title':'日韩大牌',
                     'theme':'default',
                     'order': 2,
                     'desc':'UNIQLO, Muji...',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_brand)
     }
    
    node_4 = {
                     'name':'china',
                     'title':'朝内甚大牌',
                     'theme':'default',
                     'order': 3,
                     'desc':'...',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_brand)
     }
    
    yield nodes.insert([node_1, node_2, node_3, node_4], True)
    
    s_city = {
                     'name':'city',
                     'title':'爱城市',
                     'order': 5,
                     'created': datetime.now(),
                     'updated': datetime.now(),
     }
    r_city = yield sections.insert(s_city, True)
    
    node_1 = {
                     'name':'beijing',
                     'title':'帝都',
                     'theme':'default',
                     'order': 0,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_city)
     }
    
    node_2 = {
                     'name':'shanghai',
                     'title':'魔都',
                     'theme':'default',
                     'order': 1,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_city)
     }
    
    node_3 = {
                     'name':'nanjing',
                     'title':'故都',
                     'theme':'default',
                     'order': 2,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_city)
     }
    
    node_4 = {
                     'name':'hefei',
                     'title':'合肥',
                     'theme':'default',
                     'order': 3,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_city)
     }
    
    yield nodes.insert([node_1, node_2, node_3, node_4], True)
    
    s_dev = {
                     'name':'dev',
                     'title':'爱代码',
                     'order': 6,
                     'created': datetime.now(),
                     'updated': datetime.now(),
     }
    r_dev = yield sections.insert(s_dev, True)
    
    node_1 = {
                     'name':'programing',
                     'title':'程序',
                     'theme':'default',
                     'order': 0,
                     'desc':'我们都是代码工, 每一行代码才创造1一个bug',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_dev)
     }
    
    node_2 = {
                     'name':'architect',
                     'title':'架构',
                     'theme':'default',
                     'order': 1,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_dev)
     }
    node_3 = {
                     'name':'server',
                     'title':'服务器',
                     'theme':'default',
                     'order': 2,
                     'desc':'Linux, Windows, Unix, OSx...',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_dev)
     }
    yield nodes.insert([node_1, node_2, node_3], True)
    
    s_game = {
                     'name':'game',
                     'title':'爱游戏',
                     'order': 7,
                     'created': datetime.now(),
                     'updated': datetime.now(),
     }
    r_game = yield sections.insert(s_game, True)
    
    node_1 = {
                     'name':'xbox',
                     'title':'Xbox系',
                     'theme':'default',
                     'order': 0,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_game)
     }
    
    node_2 = {
                     'name':'wii',
                     'title':'Wii系',
                     'theme':'default',
                     'order': 1,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_game)
     }
    
    node_3 = {
                     'name':'ps',
                     'title':'PS系',
                     'theme':'default',
                     'order': 2,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_game)
     }
    
    node_4 = {
                     'name':'pc',
                     'title':'PC系',
                     'theme':'default',
                     'order': 3,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_game)
     }
    
    node_5 = {
                     'name':'nds',
                     'title':'NDS系',
                     'theme':'default',
                     'order': 4,
                     'desc':'',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_game)
     }
    yield nodes.insert([node_1, node_2, node_3, node_4, node_5], True)
    ###end
    
    
    s_intern = {
                     'name':'intern',
                     'title':'内部',
                     'order': 8,
                     'created': datetime.now(),
                     'updated': datetime.now(),
     }
    
    r_intern = yield sections.insert(s_intern, True)

    node_1 = {
                     'name':'suggest',
                     'title':'领导指示',
                     'theme':'default',
                     'order': 0,
                     'desc':'欢迎各位领导对我们的工作给与重要的批评的指导',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_intern)
     }
    node_2 = {
                     'name':'private',
                     'title':'内部事务',
                     'theme':'default',
                     'order': 1,
                     'desc':'',
                     'acl':['root'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, r_intern)
     }
    yield nodes.insert([node_1, node_2], True)
    

if __name__ == '__main__':
    example().addCallback(lambda ign: reactor.stop())
    reactor.run()
